﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using App.Web.ViewModels;

namespace App.Web.Utility
{
    public static class UserInfo
    {
        public static bool IsAdmin
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfAdmin)
                    return true;
                return false;
            }
        }
        public static bool IsSiteUser
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfSiteUser)
                    return true;
                return false;
            }
        }
        public static bool IsCompanyUser
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Company != null)
                    return true;
                return false;
            }
        }
        public static bool IsCompanyAdmin
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Company != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfCompanyAdmin)
                    return true;
                return false;
            }
        }
        public static bool IsCompanyEmployeeUser
        {
            get
            {
                if (SessionCache.CurrentUser != null && SessionCache.CurrentUser.Company != null && SessionCache.CurrentUser.GroupID == ConfigReader.UserGroupIDOfCompanyUser)
                    return true;
                return false;
            }
        }

        public static String GetUserType()
        {
            if (SessionCache.CurrentUser != null)
            {                
                GroupViewModel group = ApplicationCache.UserGroups.FirstOrDefault(P => P.ID == SessionCache.CurrentUser.GroupID);
                return group.Name;
            }
            return "Not Logged In";
        }
    }
}